from web.template import CompiledTemplate, ForLoop


def guestbook():
    loop = ForLoop()
    _dummy  = CompiledTemplate(lambda: None, "dummy")
    join_ = _dummy._join
    escape_ = _dummy._escape

    def __template__ (comments):
        yield '', join_('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n')
        yield '', join_('<html xmlns="http://www.w3.org/1999/xhtml">\n')
        yield '', join_('<html>\n')
        yield '', join_('<body>\n')
        yield '', join_('<div id="css_select_1">\n')
        yield '', join_('<p>\xe7\x95\x99\xe8\xa8\x80\xe6\x9d\xbf</p>\n')
        yield '', join_('</div>\n')
        yield '', join_('\n')
        yield '', join_('<form method="post" action="/guestbook">\n')
        yield '', join_('<p>\xe5\xa7\x93\xe5\x90\x8d<input type="text" name="author" /><br />\n')
        yield '', join_('\xe5\x86\x85\xe5\xae\xb9<input type="text" name="content" /><br />\n')
        yield '', join_('<input type="submit" value="\xe6\x8f\x90\xe4\xba\xa4" /></p>\n')
        yield '', join_('</form>\n')
        yield '', join_('<p>\xe7\x95\x99\xe8\xa8\x80</p>\n')
        yield '', join_('<ul id="orderedlist">\n')
        for i,comment in loop.setup(enumerate(comments)):
            yield '', join_('<li>', escape_(comment.author, True), ' : ', escape_(comment.content, True), ',', escape_(comment.t, True), '</li>\n')
        yield '', join_('</ul>\n')
        yield '', join_('</body>\n')
        yield '', join_('</html>\n')
    return __template__

guestbook = CompiledTemplate(guestbook(), 'templates\\guestbook.html')


def index():
    loop = ForLoop()
    _dummy  = CompiledTemplate(lambda: None, "dummy")
    join_ = _dummy._join
    escape_ = _dummy._escape

    def __template__ (datas):
        yield '', join_('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> \n')
        yield '', join_('<html> \n')
        yield '', join_('<head> \n')
        yield '', join_('<title>blog</title> \n')
        yield '', join_('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> \n')
        yield '', join_('</head> \n')
        yield '', join_('<body> \n')
        yield '', join_('<div id="wrapper"> \n')
        yield '', join_('<div id="logo"> \n')
        yield '', join_('<p>Blog</p> \n')
        yield '', join_('</div> \n')
        yield '', join_('<div id="nav"> \n')
        yield '', join_('</div> \n')
        yield '', join_('<div id="nav"> \n')
        yield '', join_('<a href="/login">Log in</a> \n')
        yield '', join_('</div>\n')
        yield '', join_('<div id="article"> \n')
        for data in loop.setup(datas):
            yield '', join_('<div id="time"> \n')
            yield '', join_('<p>', escape_(data.t, True), '</p> \n')
            yield '', join_('</div> \n')
            yield '', join_('<div id="content"> \n')
            yield '', join_('<p>', escape_(data.content, True), '</p> \n')
            yield '', join_('</div> \n')
            yield '', join_('<div id="author"> \n')
            yield '', join_('<p>Post by ', escape_(data.author, True), '</p> \n')
            yield '', join_('</div> \n')
        yield '', join_('</div> \n')
        yield '', join_('</div> \n')
        yield '', join_('<div id="copyright"> \n')
        yield '', join_('<p>Copyright &copy; 2008 otherrrr. All rights reserved.</p> \n')
        yield '', join_('</div> \n')
        yield '', join_('</div> \n')
        yield '', join_('</body> \n')
        yield '', join_('</html>\n')
    return __template__

index = CompiledTemplate(index(), 'templates\\index.html')


def listnovel():
    loop = ForLoop()
    _dummy  = CompiledTemplate(lambda: None, "dummy")
    join_ = _dummy._join
    escape_ = _dummy._escape

    def __template__ (novels):
        yield '', join_('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n')
        yield '', join_('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n')
        yield '', join_('<html xmlns="http://www.w3.org/1999/xhtml">\n')
        yield '', join_('<html>\n')
        yield '', join_('<body>\n')
        yield '', join_('<div id="css_select_1">\n')
        yield '', join_('<p>\xe7\x95\x99\xe8\xa8\x80\xe6\x9d\xbf</p>\n')
        yield '', join_('</div>\n')
        yield '', join_('\n')
        yield '', join_('<html><head></head><body>\n')
        yield '', join_('<form method="POST" enctype="multipart/form-data" action="">\n')
        yield '', join_('<input type="file" name="myfile" />\n')
        yield '', join_('<br/>\n')
        yield '', join_('<input type="submit" />\n')
        yield '', join_('</form>\n')
        yield '', join_('</body></html>\n')
        yield '', join_('<p>\xe7\x95\x99\xe8\xa8\x80</p>\n')
        yield '', join_('<ul id="orderedlist">\n')
        for i,novel in loop.setup(enumerate(novels)):
            yield '', join_('<li>', escape_(i, True), ' : <a href ="/show/', escape_(novel.name, True), '">', escape_(novel.name, True), '</a></li>\n')
        yield '', join_('</ul>\n')
        yield '', join_('</body>\n')
        yield '', join_('</html>\n')
    return __template__

listnovel = CompiledTemplate(listnovel(), 'templates\\listnovel.html')


def login():
    loop = ForLoop()
    _dummy  = CompiledTemplate(lambda: None, "dummy")
    join_ = _dummy._join
    escape_ = _dummy._escape

    def __template__():
        yield '', join_('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> \n')
        yield '', join_('<html> \n')
        yield '', join_('<head> \n')
        yield '', join_('<title>Log in</title> \n')
        yield '', join_('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> \n')
        yield '', join_('</head> \n')
        yield '', join_('<body> \n')
        yield '', join_('<div id="wrapper"> \n')
        yield '', join_('<div id="logo"> \n')
        yield '', join_('<p>Blog</p> \n')
        yield '', join_('</div> \n')
        yield '', join_('<div id="post"> \n')
        yield '', join_('<form action="/login" method="post"> \n')
        yield '', join_('<label for="post_username">Username</label><br /> \n')
        yield '', join_('<input id="post_username" name="post_username"><br /> \n')
        yield '', join_('<label for="post_password">Password</label><br /> \n')
        yield '', join_('<input id="post_password" name="post_password" type="password"><br /> \n')
        yield '', join_('<input type="submit" name="post_login" value="Login" /> \n')
        yield '', join_('</form> \n')
        yield '', join_('</div> \n')
        yield '', join_('<div id="copyright"> \n')
        yield '', join_('<p>Copyright &copy; 2008 otherrrr. All rights reserved.</p> \n')
        yield '', join_('</div> \n')
        yield '', join_('</div> \n')
        yield '', join_('</body> \n')
        yield '', join_('</html>\n')
    return __template__

login = CompiledTemplate(login(), 'templates\\login.html')


def register():
    loop = ForLoop()
    _dummy  = CompiledTemplate(lambda: None, "dummy")
    join_ = _dummy._join
    escape_ = _dummy._escape

    def __template__(form):
        yield '', join_('\n')
        yield '', join_('<h1>Register</h1>\n')
        yield '', join_('<form method="POST">\n')
        yield '', join_('    ', escape_(form.render(), False), '\n')
        yield '', join_('</form>\n')
    return __template__

register = CompiledTemplate(register(), 'templates\\register.html')

